type message
	''Destination of message (channel or user)
	dest as zstring * 24
	
	''our actual message
	msg as zstring * 256

	'' this determines what kind of message this sends
	'' 0 as no message (don't bother sending anything)
	'' 1 to set as normal message (privmsg)
	'' 2 to send notice
	'' 3 to change modes (channel or otherwise)
	'' 4 as raw server command (dest will be ignored)
	msgtype as ubyte
end type


type queue
	
	''Add item to queue
	''returns 1 if successful, 0 if it fucked up
	declare function enqueue(item as message) as ubyte 

	''Remove item from queue
	''same returns as enqueue
	''it also places item from queue into item
	declare function dequeue(byref item as message) as ubyte
	
	''The queue tail (pointer)
	dim as integer tail

	''This amazing thing is what holds the whole thing toghether
	''It is the queue itself
	''It holds a maximum of 32,762 items (all you'll ever need anyways)
	dim as message queuehold(32762)

	declare constructor()
end type

constructor queue()
	
	tail=-1

end constructor

function queue.enqueue(item as message) as ubyte
	
	''Is tail full?
	if tail >= 32762 then return 0
	
	''Increment tail
	tail += 1
	
	''Store item in queue
	queuehold(tail).dest=item.dest
	queuehold(tail).msg=item.msg
	queuehold(tail).msgtype=item.msgtype
	
	''Yes, it workeded
	return 1
end function
	
function queue.dequeue(byref item as message) as ubyte
	
	''Is tail too small?
	if tail <= -1 then return 0
	
	''get our item
	item.dest=queuehold(0).dest
	item.msg=queuehold(0).msg
	item.msgtype=queuehold(0).msgtype

	''shift all the items upfront
	for i as integer = 0 to tail
		queuehold(i).dest=queuehold(i+1).dest
		queuehold(i).msg=queuehold(i+1).msg
		queuehold(i).msgtype=queuehold(i+1).msgtype
	next

	''Decrement tail
	tail -= 1
	
	''woot, we did it
	return 1
end function

